<template>
  <el-form ref="form" :model="form" :rules="rules" label-width="80px" style="width:50%">
    <el-form-item label="企业名称" prop="name">
      <el-input v-model="form.name" placeholder="请输入企业名称"></el-input>
    </el-form-item>
    <el-form-item label="证件类型" prop="type">
      <el-select v-model="form.type" placeholder="请选择证件类型">
        <el-option label="统一社会信用代码" value="统一社会信用代码"></el-option>
        <el-option label="组织机构代码" value="组织机构代码"></el-option>
        <el-option label="其他证件类型" value="其他证件类型"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="成立日期" prop="date">
      <el-date-picker type="date" placeholder="选择日期" v-model="form.date" style="width: 100%;"></el-date-picker>
    </el-form-item>
    <el-form-item label="证件号码" prop="num">
      <el-input v-model="form.num" placeholder="请输入证件号码"></el-input>
    </el-form-item>

    <el-form-item label="注册资本" prop="capital">
      <el-input v-model="form.capital" placeholder="请输入注册资本"></el-input>
    </el-form-item>
    <el-form-item label="详细地址" prop="address">
      <el-input v-model="form.address" placeholder="请输入详细地址"></el-input>
    </el-form-item>
    <el-form-item label="职工人数" prop="peonum">
      <el-input v-model="form.peonum" placeholder="请输入职工人数"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit('form')">立即添加</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import moment from 'moment';

  export default {
    data() {
      return {
        form: {
          id: '',
          name: '',
          type: '',
          date: '',
          num: '',
          capital: '',
          address: '',
          peonum: ''
        },
        rules: {
          name: [
            { required: true, message: '请输入企业名称', trigger: 'blur' },
          ],
          type: [
            { required: true, message: '请选择证件类型', trigger: 'blur' },
          ],
          date: [
            { required: true, message: '请选择成立日期', trigger: 'blur' },
          ],
          num: [
            { required: true, message: '请输入证件号码', trigger: 'blur' },
          ],
          capital: [
            { required: true, message: '请输入注册资本', trigger: 'blur' },

          ],
          address: [
            { required: true, message: '请输入详细地址', trigger: 'blur' },
          ],
          peonum: [
            { required: true, message: '请输入职工人数', trigger: 'blur' },

          ],
        }
      }
    },
    methods: {
      onSubmit(formName) {
        this.$axios({
          url: '',
          methods: "",
          data: {

          }
        })


        this.$axios.post('/api/AddEnterpriseController/addNewEnterprise', this.$qs.stringify({
          enterpriseId: this.form.id,
          enterpriseName: this.form.name,
          cardType: this.form.type,
          enterpriseDate: moment(this.form.date).format("YYYY-MM-DD"),
          cardId: this.form.num,
          capital: this.form.capital,
          address: this.form.address,
          workes: this.form.peonum
        })).then(res => {
          console.log(res.data)
          if (res.data.code == "200") {
            this.$message({
              message: "添加成功",
              type: "success"
            })
          }
        })
        // this.$axios({
        //   url: '/api/AddEnterpriseController/addNewEnterprise',
        //   methods: "post",
        //   data: {
        //     id: this.form.id,
        //     name: this.form.name,
        //     type: this.form.type,
        //     date: this.form.data,
        //     num: this.form.num,
        //     capital: this.form.capital,
        //     address: this.form.address,
        //     peonum: this.form.peonum
        //   }
        // }).then(res => {
        //   console.log(res.data)
        //   if (res.data.code == "200") {
        //     this.$message({
        //       message: "添加成功",
        //       type: "success"
        //     })
        //   }
        // })
        this.$refs[formName].validate((valid) => {  //rules判断
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
        console.log(this.form);
        this.form.date = moment(this.form.date).format("YYYY-MM-DD")
        let obj1 = this.form
        console.log(obj1);
        if (obj1.name === '' || obj1.type === '' || obj1.date === '' || obj1.num === '' || obj1.capital === '' || obj1.address === '' || obj1.peonum === '') {
          this.$message({
            message: '您输入的信息不全，请输入所有信息！',
            type: 'warning'
          });
        } else {

        }
      }
    }
  }
</script>